<template>
  <div :class="className" :style="{height:height,width:width}"></div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: "PieEcharts",
  watch: {
    chartData: {
      handler() {
        this.initChart();
      },
      deep: true
    }
  },
  props: {
    className: {
      type: String,
      default: "chart"
    },
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "300px"
    },
    chartTitle: {
      type: String,
      default: "Title"
    },
    chartData: Array
  },
  data() {
    return {
      chart: null
    }
  }, methods: {
    initChart() {
      this.chart = echarts.init(this.$el);
      this.chart.setOption({
        title: {
          text: this.chartTitle,
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        series: [
          {
            type: 'pie',
            radius: '50%',
            data: this.chartData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }, true)
    }
  }
}
</script>

<style scoped>

</style>